#include "process.h"
#include <time.h>
#include <stdlib.h>
typedef void (*ptr)(double,double);

double speed[5] = {1.0,2.0,0.1,0.2,0.3};

void download(double total,ptr pr )
{
    srand(time(NULL));
    int random = rand()%5;
    double current = 0;
    while(current <= total)
    {
        pr(total,current);
        if(current == total)
        {
            break;
        }
        usleep(1000);
        current += speed[random];
        if(current > total)
        {
            current = total;
        }
    }
    printf("\n");
}

void upload(double total,ptr pr )
{
    double current = 0;
    double speed = 1.0;
    while(current <= total)
    {
        pr(total,current);
        if(current == total)
        {
            break;
        }
        usleep(10000);
        current += speed;
        if(current > total)
        {
            current = total;
        }
    }
    printf("\n");
}

int main()
{
    download(1024,Flushprocess);
    upload(512,Flushprocess);
    return 0;
}
